home *** CD-ROM | disk | FTP | other *** search
/ OpenGL Superbible (2nd Edition) / OpenGL SuperBible e2.iso / tools / FLTK-1.0.6 / src / Fl_Pack.cxx < prev    next >
Encoding:
C/C++ Source or Header  |  1999-01-07  |  3.3 KB  |  110 lines

  1. //
  2. // "$Id: Fl_Pack.cxx,v 1.6 1999/01/07 19:17:24 mike Exp $"
  3. //
  4. // Packing widget for the Fast Light Tool Kit (FLTK).
  5. //
  6. // Copyright 1998-1999 by Bill Spitzak and others.
  7. //
  8. // This library is free software; you can redistribute it and/or
  9. // modify it under the terms of the GNU Library General Public
  10. // License as published by the Free Software Foundation; either
  11. // version 2 of the License, or (at your option) any later version.
  12. //
  13. // This library is distributed in the hope that it will be useful,
  14. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16. // Library General Public License for more details.
  17. //
  18. // You should have received a copy of the GNU Library General Public
  19. // License along with this library; if not, write to the Free Software
  20. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  21. // USA.
  22. //
  23. // Please report all bugs and problems to "fltk-bugs@easysw.com".
  24. //
  25.  
  26. // Based on code by Curtis Edwards
  27. // Group that compresses all it's children together and resizes to surround
  28. // them on each redraw (only if box() is zero)
  29. // Bugs: ?
  30.  
  31. #include <FL/Fl.H>
  32. #include <FL/Fl_Pack.H>
  33. #include <FL/fl_draw.H>
  34.  
  35. Fl_Pack::Fl_Pack(int x,int y,int w ,int h,const char *l)
  36. : Fl_Group(x, y, w, h, l) {
  37.   resizable(0);
  38.   spacing_ = 0;
  39.   // type(VERTICAL); // already set like this
  40. }
  41.  
  42. void Fl_Pack::draw() {
  43.   int tx = x()+Fl::box_dx(box());
  44.   int ty = y()+Fl::box_dy(box());
  45.   int tw = w()-Fl::box_dw(box());
  46.   int th = h()-Fl::box_dh(box());
  47.   int current_position = horizontal() ? tx : ty;
  48.   int maximum_position = current_position;
  49.   uchar d = damage();
  50.   Fl_Widget*const* a = array();
  51.   for (int i = children(); i--;) {
  52.     Fl_Widget* o = *a++;
  53.     if (o->visible()) {
  54.       int X,Y,W,H;
  55.       if (horizontal()) {
  56.         X = current_position;
  57.         W = o->w();
  58.         Y = ty;
  59.         H = th;
  60.       } else {
  61.         X = tx;
  62.         W = tw;
  63.         Y = current_position;
  64.         H = o->h();
  65.       }
  66.       if (spacing_ && current_position>maximum_position &&
  67.         (X != o->x() || Y != o->y() || d&FL_DAMAGE_ALL)) {
  68.         fl_color(color());
  69.         if (horizontal())
  70.       fl_rectf(maximum_position, ty, spacing_, th);
  71.         else
  72.       fl_rectf(tx, maximum_position, tw, spacing_);
  73.       }
  74.       if (X != o->x() || Y != o->y() || W != o->w() || H != o->h()) {
  75.         o->resize(X,Y,W,H);
  76.         o->clear_damage(FL_DAMAGE_ALL);
  77.       }
  78.       if (d&FL_DAMAGE_ALL) draw_child(*o); else update_child(*o);
  79.       // child's draw() can change it's size, so use new size:
  80.       current_position += (horizontal() ? o->w() : o->h());
  81.       if (current_position > maximum_position)
  82.         maximum_position = current_position;
  83.       current_position += spacing_;
  84.     }
  85.   }
  86.  
  87.   if (horizontal()) {
  88.     if (maximum_position < tx+tw) {
  89.       fl_color(color());
  90.       fl_rectf(maximum_position, ty, tx+tw-maximum_position, th);
  91.     }
  92.     tw = maximum_position-tx;
  93.   } else {
  94.     if (maximum_position < ty+th) {
  95.       fl_color(color());
  96.       fl_rectf(tx, maximum_position, tw, ty+th-maximum_position);
  97.     }
  98.     th = maximum_position-ty;
  99.   }
  100.  
  101.   tw += Fl::box_dw(box()); if (tw <= 0) tw = 1;
  102.   th += Fl::box_dh(box()); if (th <= 0) th = 1;
  103.   if (tw != w() || th != h()) {Fl_Widget::resize(x(),y(),tw,th); d = FL_DAMAGE_ALL;}
  104.   if (d&FL_DAMAGE_ALL) draw_box();
  105. }
  106.  
  107. //
  108. // End of "$Id: Fl_Pack.cxx,v 1.6 1999/01/07 19:17:24 mike Exp $".
  109. //
  110.